<script type="text/javascript" SRC="/js/merchant/asn_create.js"></script>
<script type="text/javascript">
var reference_no = '';
jQuery.extend(jQuery.validator.messages, {
	  required: "<img src='/images/error.jpg'><{$languages['REQUIRED']}>.",
	  remote:"<img src='/images/error.jpg'><{$languages['EXISTS']}>"
});
$(function(){
	initData(0); //初始化分页数据
		
	$("#tipDialog").dialog({
		autoOpen:false,
		modal:true,
		width:300,
		show:"slide",
		buttons:{
			"Close":function(){
				$(this).dialog("close");
				
			}
		}
	});
	
	$("#editForm").validate({
		rules:{
			'reference_no':{
				required: false,
				remote:{
					url:"/merchant/receiving/check-refno",
					type: "post",               //数据发送方式
  					dataType: "json",           //接受数据格式  
					data:{
						reference_no:function() {return $('[name=reference_no]').val();}
					}
				}
			}
		},
		errorPlacement:function(error, element){
			element.parent().parent().children(".right").html(error);  
		},
		success:function(label){
			label.parent().parent().children(".right").html("<img src='/images/yes.gif'>");
		}
	});
	
});


function checkProduct(){
	 if($(".product_sku").length==0){
		$(".productError").html("<img src='/images/error.jpg'><{$languages['PRODUCT']}> <{$languages['REQUIRED']}>!");
		$(".productError").show();
		return false;
	 }
	 $(".productError").html("");
	 $(".productError").hide();
	 return true;
}

function submitForm(){
	var formData =$('#editForm').serialize();

	if(!$("#editForm").valid() | !checkProduct()){
		return false;
	}
    
	$.ajax({
		type: "POST",
		async: false,
		dataType: "json",
		url: "/merchant/receiving/create",
		data:formData,
		success: function(json) {
			var html ="";
            if(json.ask=='Success'){
                $("#tipDialog").html('ASNNo: '+json.receiving_code+' Success!');
            }else{               
				$("#tipDialog").html(' Add failed! '+json.msg);
            }
            clear();
            $("#tipDialog").dialog("open");
		}
	});
}

function clear(){
	$('[name=reference_no]').val('');
	$('[name=instructions]').val('');
	$('#ProductList').html('');
	$('.all_weight').html('');
}

function checkAll(obj){
	if(jQuery (obj).attr("checked")=='checked'){
		jQuery ('.checked').attr('checked',true);
	}else{
	    jQuery ('.checked').attr('checked',false);
	}
}

</script>
<style>

.cell2 {
    background: url("") repeat-y scroll right top transparent;
    float: left;
    height: 25px;
    line-height: 25px;
    overflow: hidden;
    text-align: center;
}

</style>
<div class="position"><a href='/default/index'><{$languages['HOME']}></a> &gt; <a href='/merchant/my-account'><{$languages['MERCHANT_CENTER']}></a>  &gt; <{$languages['OPERATION']}> &gt; <{$languages['CREATE_ASN']}></div>

<form id="editForm"  method="POST" >
<h4><{$languages['CREATE_ASN']}></h4>
<div style="margin-bottom:10px">
    <{if $languages['LANGUAGEID']==1}>
    <p>
        You need to create an ASN (Advanced Shipping Notice) to notify us of
        your incoming stock. <br> Input the quantity of each product which
        you will be sending and then click the "Create ASN" button. <br>
        Note: If your product is not listed below, Try to <a href="/merchant/product/create" style="text-decoration: underline">
        Create New Product</a> first and then make sure it was Activated.
    </p>
    <{else}>
    <p>
        如果您还没有产品，请先<a href="/merchant/product/create" style="text-decoration:underline" > 创建产品</a> 并且激活产品.
    </p>
    <{/if}>
</div>

<div class="tab-div">

	<div class="row" style="line-height:12px;">
		<div class="middle">			
			<span class="button-2"  onclick="OpenProductDiv()"><{$languages['SELECT_PRODUCT_LIST']}></span>
			<span class="red">&nbsp;&nbsp;</span>
		</div>
		<div class="right"></div>
	</div>
	
	<div class="row" id="OrderProduct">
		<div class="row height25 row-header">
			<div class="cell sort" style="width:15%" >SKU</div>
			<div class="cell sort" style="width:15%" ><{$languages['SKUNAME']}></div>
            <div class="cell sort" style="width:15%" ><{$languages['CHINESENAME']}></div>
			<div class="cell sort" style="width:15%" ><{$languages['CATEGORY']}></div>
			<div class="cell sort" style="width:8%" ><{$languages['QUANTITY']}></div>
			<div class="cell sort" style="width:10%" ><{$languages['WEIGHT']}></div>
			<div class="cell2" style="width:7%"><{$languages['ACTIONS']}></div>
		</div>
		<div id="ProductList"  class="row"></div>
		<div class="row height25">
			<div class="cell" style="width:78%;text-align:right" ><{$languages['TOTAL_WEIGHT']}> &nbsp; </div>
			<div class="cell2 all_weight" style="width:22%;text-align:left" ></div>
		</div>
	</div>
	<div class="productError row height25" style="display:none"></div>

</div>

<h4><{$languages['ADDITIONAL_INFO']}></h4>
<div class="tab-div">

    <div class="row">
		<div class="left"  style="width:20%;line-height:25px;"><{$languages['REFERENCE_NO']}>:</div>
    	<div class="middle">
    		<input type="text" class="inputText remote" name="reference_no" value="" style="width:235px;" />
    		<span class="red">&nbsp;&nbsp;*</span>
    	</div>
    	<div class="right">&nbsp;</div>
	</div>

    
	<div class="row" style="padding-top:5px">
		<div class="left"  style="width:20%;height:95px;"><{$languages['INSTRUCTIONS']}>:</div>
    	<div class="middle">
    		<textarea cols="38" rows="5" name="instructions" ></textarea>
			<input type="hidden" name="receiving_id" value="" />
    		<span class="red">&nbsp;&nbsp;</span>
    	</div>
    	<div class="right">&nbsp;</div>
	</div>
    
    <div class="row" style="height:40px;align:center">

    	<div style="margin-top:10px;margin-left:150px">
    		<span class="button-2"  onclick="submitForm()"><{$languages['SUBMIT']}></span>
    		<input type="hidden" name="shipping_fee_estimate" value=""/>
    	</div>
    </div>
</div>
</form>

<div class="prdouctDiv" style="display:none" title="Product List">
<{include file='merchant/orders/warehouse-products-list.tpl'}>
</div>

<div id="tipDialog" style="display:none" title="Tip"></div>